package com.comp6521.project01;

import java.io.File;
import java.util.List;

public class LiMain {

	/*  
	 * 2 arguments
	 * first argument: inputfile ex: d:\\data\\small.dat
	 * second argument: output folder  ex: d:\\data
	 */
	public static void main(String[] args) throws Exception {
		if(args.length!=2){
			System.out.println("arguments are not valid");
			return;
		}
		long startTime = System.currentTimeMillis();
		//read data, sort, output sorted data to files
		LiPhaseOne phaseOne = new LiPhaseOne();
		List<String> fileNameList = phaseOne.generateSortedFile(args[0], args[1]);
		//merge
		LiPhaseTwo phaseTwo = new LiPhaseTwo();
		phaseTwo.merge(fileNameList, args[1]);
		//delete temp files
		for(String fileName: fileNameList){
			new File(fileName).delete();
		}
		long finishTime = System.currentTimeMillis();
		double totalTime = (double)(finishTime - startTime) / 1000;
		System.out.println("total time: " + totalTime + " seconds");
	}

}
